package com.app.biz.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.app.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.app.common.annotation.Log;
import com.app.common.core.controller.BaseController;
import com.app.common.core.domain.AjaxResult;
import com.app.common.enums.BusinessType;
import com.app.biz.domain.BizIndustrialSectorMetrics;
import com.app.biz.service.IBizIndustrialSectorMetricsService;
import com.app.common.utils.poi.ExcelUtil;
import com.app.common.core.page.TableDataInfo;

/**
 * 分行业企业主要经济指标临时Controller
 *
 * @author SangGuangCan
 * @date 2024-01-02
 */
@RestController
@RequestMapping("/biz/metrics")
public class BizIndustrialSectorMetricsController extends BaseController
{
    private final IBizIndustrialSectorMetricsService bizIndustrialSectorMetricsService;

    @Autowired
    public BizIndustrialSectorMetricsController(IBizIndustrialSectorMetricsService bizIndustrialSectorMetricsService){
        this.bizIndustrialSectorMetricsService = bizIndustrialSectorMetricsService;
    }

    /**
     * 查询分行业企业主要经济指标临时列表
     */
    @PreAuthorize("@ss.hasPermi('biz:metrics:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizIndustrialSectorMetrics bizIndustrialSectorMetrics)
    {
        startPage();
        List<BizIndustrialSectorMetrics> list = bizIndustrialSectorMetricsService.selectBizIndustrialSectorMetricsList(bizIndustrialSectorMetrics);
        return getDataTable(list);
    }

    /**
     * 导出分行业企业主要经济指标临时列表
     */
    @PreAuthorize("@ss.hasPermi('biz:metrics:export')")
    @Log(title = "分行业企业主要经济指标临时", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizIndustrialSectorMetrics bizIndustrialSectorMetrics)
    {
        List<BizIndustrialSectorMetrics> list = bizIndustrialSectorMetricsService.selectBizIndustrialSectorMetricsList(bizIndustrialSectorMetrics);
        ExcelUtil<BizIndustrialSectorMetrics> util = new ExcelUtil<BizIndustrialSectorMetrics>(BizIndustrialSectorMetrics.class);
        util.exportExcel(response, list, "分行业企业主要经济指标临时数据");
    }

    /**
     * 获取分行业企业主要经济指标临时详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:metrics:query')")
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(bizIndustrialSectorMetricsService.selectBizIndustrialSectorMetricsByBaseId(baseId));
    }

    /**
     * 新增分行业企业主要经济指标临时
     */
    @PreAuthorize("@ss.hasPermi('biz:metrics:add')")
    @Log(title = "分行业企业主要经济指标临时", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizIndustrialSectorMetrics bizIndustrialSectorMetrics)
    {
        return toAjax(bizIndustrialSectorMetricsService.insertBizIndustrialSectorMetrics(bizIndustrialSectorMetrics));
    }

    /**
     * 修改分行业企业主要经济指标临时
     */
    @PreAuthorize("@ss.hasPermi('biz:metrics:edit')")
    @Log(title = "分行业企业主要经济指标临时", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizIndustrialSectorMetrics bizIndustrialSectorMetrics)
    {
        return toAjax(bizIndustrialSectorMetricsService.updateBizIndustrialSectorMetrics(bizIndustrialSectorMetrics));
    }

    /**
     * 删除分行业企业主要经济指标临时
     */
    @PreAuthorize("@ss.hasPermi('biz:metrics:remove')")
    @Log(title = "分行业企业主要经济指标临时", businessType = BusinessType.DELETE)
    @DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(bizIndustrialSectorMetricsService.deleteBizIndustrialSectorMetricsByBaseIds(baseIds));
    }

    /**
     * <p>
     *     将临时表中的数据迁移到正式表虽
     * </p>
     * @return
     */
    @Anonymous
    @PostMapping("/transferDataInOneClick")
    public AjaxResult transferDataInOneClick(){

        return toAjax(bizIndustrialSectorMetricsService.transferDataInOneClick());
    }

    /**
     * <p>
     *     清空所有的全社会用电量数据
     * </p>
     * @return
     */
    @DeleteMapping("/clearAllTableData")
    public AjaxResult clearAllTableData(){
        bizIndustrialSectorMetricsService.clearAllTableData();
        return AjaxResult.success();
    }
}
